﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace txcloud.sdk.Lighthouse
{
    using TencentCloud.Lighthouse.V20200324.Models;
    public class Firewall
    {
        public IList<FirewallRule> Rules { get; set; }
        internal ulong? FirewallVersion { get; set; }
        internal Firewall(DescribeFirewallRulesResponse rep)
        {
            FirewallVersion= rep.FirewallVersion;
            Rules = rep.FirewallRuleSet.Select(t => {
                var rule = new FirewallRule
                {
                    Action = t.Action,
                    FirewallRuleDescription = t.FirewallRuleDescription,
                    Port = t.Port,
                    Protocol = t.Protocol,
                };
                if (string.IsNullOrEmpty(t.CidrBlock)) rule.Ipv6CidrBlock = t.Ipv6CidrBlock;
                else rule.CidrBlock = t.CidrBlock;

                return rule;
            }).ToList();
        }
        public void ClearVersion()
        {
            this.FirewallVersion = null;
        }
    }
}
